#include<iostream>
#include<cstring>
using namespace std;

class Account
{
private:
    static float count; // 账户总余额
    static float interestRate;
    string accno, accname;
    float balance;
public:
    Account(){};
    Account(string ac, string na, float ba);
    ~Account(){};
    friend void update(Account &a);
    void deposit(float amount); // 存款
    void withdraw(float amount); // 取款
    float getBalance(); // 获取账户余额
    void show(); // 显示账户所以基本信息
    static float getCount(); // 获取账户总余额
    static void setInterestRate(float rate); // 设置利率
    static float getInterestRate(); // 获取利率
};

float Account::count=0;
float Account::interestRate=0;

Account::Account(string ac,string na,float ba)
{
    accno=ac,accname=na;
    balance=ba;
}

void Account::deposit(float amount)
{
    balance+=amount;
}

void Account::withdraw(float amount)
{
    balance-=amount;
}

float Account::getBalance()
{
    return balance;
}

void update(Account &a)
{
    a.balance+=a.balance*a.getInterestRate();
    //cout<<a.balance<<" ";
    a.count+=a.balance;
}

void Account::show()
{
    cout<<accno<<" "<<accname<<" ";
}

void Account::setInterestRate(float rate)
{
    interestRate=rate;
}

float Account::getCount()
{
    return count;
}

float Account::getInterestRate()
{
    return interestRate;
}

int main()
{
    float rate;
    string accno,accname;
    float balance,amount;
    cin>>rate;
    int t,sum=0;
    cin>>t;
    Account *p=new Account[t];
    for(int i=0;i<t;i++)
    {
        cin>>accno>>accname>>balance;
        p[i]=Account(accno,accname,balance);
        p[i].setInterestRate(rate);
        p[i].show();
        cin>>amount;
        p[i].deposit(amount);
        cout<<p[i].getBalance()<<" ";
        update(p[i]);
        cout<<p[i].getBalance()<<" ";
        cin>>amount;
        p[i].withdraw(amount);
        cout<<p[i].getBalance()<<endl;
        sum+=p[i].getBalance();
        //delete p[i];
    }
    delete []p;
    cout<<sum;
    return 0;

}

